<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Student;

/**
 * StudentSearch represents the model behind the search form about `app\models\Student`.
 */
class StudentSearch extends Student
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['xs_id', 'xs_age', 'yey_id', 'bj_id', 'ls_id'], 'integer'],
            [['xs_name', 'xs_xb', 'xs_height', 'xs_weight', 'update_time', 'update_people'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Student::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'xs_id' => $this->xs_id,
            'xs_age' => $this->xs_age,
            'yey_id' => $this->yey_id,
            'bj_id' => $this->bj_id,
            'ls_id' => $this->ls_id,
            'update_time' => $this->update_time,
        ]);

        $query->andFilterWhere(['like', 'xs_name', $this->xs_name])
            ->andFilterWhere(['like', 'xs_xb', $this->xs_xb])
            ->andFilterWhere(['like', 'xs_height', $this->xs_height])
            ->andFilterWhere(['like', 'xs_weight', $this->xs_weight])
            ->andFilterWhere(['like', 'update_people', $this->update_people]);

        return $dataProvider;
    }
}
